<?php

require './googlechartphplib-0.5/lib/GoogleChart.php';
require './googlechartphplib-0.5/lib/GoogleBarChart.php';
//$debug=1;
//get data
$db_obj = mysql_connect('localhost', 'smatool', 'warming') or die(mysql_error());
$qrymax=0;
$qrymin=0;
$city_data_colors="";
$city_data_label="";

    
mysql_select_db('local_data', $db_obj);

function imp($char,$tag){
	foreach($char as $key=>$value){
	$char[$key] = $value;
	}
	$char = implode($tag,$char);
	return $char;
}

	$sql = 'SELECT day(DateTime) as dDay,truncate(sum(CurrentPower)*(5/60),0) as DayYield FROM DayData WHERE DateTime >= now() - interval 1 month group by date(DateTime)';

	$query = mysql_query($sql);
	while($row = mysql_fetch_array($query)){
	$date[] = $row['dDay'];
	$data[] = $row['DayYield'];

	}
	
	//$sql='SELECT distinct day(DateTime) as dHour FROM DayData WHERE DateTime >= NOW() - interval 1 month';
	//$query = mysql_query($sql);
	//while($row = mysql_fetch_array($query)){
	//$date[] = $row['dHour'];
	//}

//$chart = new GoogleChart('bvs', 500, 200);
$chart= new GoogleBarChart('bvs', 500, 200);
//$chart->setAutoscale(GoogleChart::AUTOSCALE_VALUES);
$chart->setAutoscale(GoogleChart::AUTOSCALE_OFF);
$chart->setGridLines(100,10);

$line = new GoogleChartData($data);
$chart->addData($line);
$chart->setScale(0,25000);

$chart->setBarWidth('a');

$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawLine(true);
$y_axis->setDrawTickMarks(true);
$y_axis->setLabels(array(null,2500,5000,7500,10000,12500,15000,17500,20000,22500,25000 ));

$y_axis->setFontSize(9);
$y_axis->setTickMarks(5);
//$y_axis->setTickColor('ffffff');
$chart->addAxis($y_axis);

$x_axis = new GoogleChartAxis('x');
$x_axis->setDrawLine(true);
$x_axis->setDrawTickMarks(false);
$x_axis->setLabels($date);
//$x_axis->setLabelPositions(0,25.8,51.8,77.6);
//$x_axis->setTickMarks(5);
//$x_axis->setFontSize(9);
$chart->addAxis($x_axis);

if ( isset($debug) ) {
	echo urldecode($chart->getUrl());
	echo '<br> <br>';
	var_dump($chart->getQuery());
	echo $chart->validate();
	echo $chart->toHtml();
}
else{
	header('Content-Type: image/png');
	echo $chart;
}
